package jangdolbaeng2.customer.dao;

import jangdolbaeng2.db.MybatisConfig;
import jangdolbaeng2.vo.DeliveryVO;
import jangdolbaeng2.vo.Product_commentVO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import oracle.sql.CLOB;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class ProductDAO {
	
	SqlSessionFactory factory = MybatisConfig.getSqlSessionFactory();
	
	public List<HashMap<String, Object>> selectAllProduct() {
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;
		
		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.selectAllProduct");
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
	}

	public List<HashMap<String, Object>> selectAllProductCategory(String category) {
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;
		
		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.selectAllProductCategory",category);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
		
	}

	public List<HashMap<String, Object>> getMDList() {
		SqlSession ss = null;
		List<HashMap<String, Object>> md_list = null;
		
		try {
			ss = factory.openSession();
			md_list = ss.selectList("product.getMDList");
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return md_list;
	}

	public HashMap<String, Object> selectAProduct(int product_seq) {
		SqlSession ss = null;
		HashMap<String, Object> product_vo = null;
		
		try {
			ss = factory.openSession();
			product_vo = ss.selectOne("product.selectAProduct", product_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_vo;
	}


	public List<HashMap<String, Object>> selectAllProductQuantity(String category) {
		
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;
		
		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.selectAllProductQuantity",category);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
	}
	
	public List<HashMap<String, Object>> selectAllProductLowPrice(String category) {
		
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;
		
		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.selectAllProductLowPrice",category);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
	}
	
	public List<HashMap<String, Object>> selectAllProductHighPrice(String category) {
		
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;
		
		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.selectAllProductHighPrice",category);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
	}

	public List<Product_commentVO> selectCommentList(int product_seq) {

		SqlSession ss = null;
		List<Product_commentVO> comment_list = null;
		
		try {
			ss = factory.openSession();
			comment_list = ss.selectList("product.selectAllComment",product_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return comment_list;
	}

	public void editProductComment(HashMap<String, Object> comment) {

		SqlSession ss = null;

		try {
			ss = factory.openSession();
			ss.update("product.editProductComment",comment);
			ss.commit();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
	}

	public Product_commentVO selectAComment(int cmt_seq) {
		SqlSession ss = null;
		Product_commentVO comment_vo = null;
		
		try {
			ss = factory.openSession();
			comment_vo = ss.selectOne("product.selectAComment", cmt_seq);
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return comment_vo;
	}

	public void deleteProductComment(int cmt_seq) {
		SqlSession ss = null;

		try {
			ss = factory.openSession();
			ss.delete("product.deleteProductComment",cmt_seq);
			ss.commit();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
	}

	public void insertProductComment(Product_commentVO comment_vo) {

		SqlSession ss = null;

		try {
			ss = factory.openSession();
			ss.insert("product.insertProductComment",comment_vo);
			ss.commit();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
	}

	public List<String> selectAllCustomer(int product_seq) {
		SqlSession ss = null;
		List<String> customer_id_list = null;

		try {
			ss = factory.openSession();
			customer_id_list = ss.selectList("product.selectAllCustomer",product_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return customer_id_list;
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public List<HashMap<String, Object>> selectAllDelivery(String customer_id) {
		SqlSession ss = null;
		List<HashMap<String, Object>> delivery_list = null;

		try {
			ss = factory.openSession();
			delivery_list = ss.selectList("product.selectAllDelivery",customer_id);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return delivery_list;
	}
	public HashMap<String, Object> selectAOrder(int order_seq){
		
		SqlSession ss = null;
		HashMap<String, Object> order_vo = null;

		try {
			ss = factory.openSession();
			order_vo = ss.selectOne("product.selectAOrder",order_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return order_vo;
	}

	public List<HashMap<String, Object>> selectAllProduct_name(int order_seq) {
		SqlSession ss = null;
		List<HashMap<String, Object>> product_name_list = null;

		try {
			ss = factory.openSession();
			product_name_list = ss.selectList("product.selectAllProduct_name",order_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_name_list;
	}

	public DeliveryVO selectADelivery(int order_seq) {
		SqlSession ss = null;
		DeliveryVO delivery_vo = null;

		try {
			ss = factory.openSession();
			delivery_vo = ss.selectOne("product.selectADelivery",order_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return delivery_vo;
	}

	public Object selectAShopBlog_photo(int shop_seq) {
		SqlSession ss = null;
		Object blog_photo = null;

		try {
			ss = factory.openSession();
			blog_photo = ss.selectOne("product.selectAShopBlog_photo",shop_seq);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return blog_photo;
	}

	public List<HashMap<String, Object>> selectAllforSearching(String keyword) {
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;

		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.selectAllforSearching",keyword);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
	}

	public List<HashMap<String, Object>> selectResultforSearching(String keyword) {
		SqlSession ss = null;
		List<HashMap<String, Object>> result_category_list = null;

		try {
			ss = factory.openSession();
			result_category_list = ss.selectList("product.selectResultforSearching",keyword);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return result_category_list;
	}

	public List<HashMap<String, Object>> getSearchCategory(HashMap<String, Object> keywords) {
		SqlSession ss = null;
		List<HashMap<String, Object>> product_list = null;

		try {
			ss = factory.openSession();
			product_list = ss.selectList("product.getTheCategoryResult",keywords);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			if(ss!=null) ss.close();
		}
		
		return product_list;
	}

}
